//  Gmof - A meta-object facility library based on OMG's EMOF 
//
//  Copyright (C) 2007 Peter Hagg <peter.hagg@iki.fi>
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//
#include <cppunit/TestAssert.h>
#include <cppunit/Test.h>
#include <cppunit/TestSuite.h>
#include <cppunit/TestCaller.h>
#include <cppunit/extensions/HelperMacros.h>

#include "../src/gmof.h"

class ClassTest : public CppUnit::TestFixture 
{
	CPPUNIT_TEST_SUITE(ClassTest);
	
	CPPUNIT_TEST(test_creation);
	CPPUNIT_TEST(test_property_creation);
	CPPUNIT_TEST(test_operation_creation);
	CPPUNIT_TEST(test_parameter_creation);
	CPPUNIT_TEST(test_comment_container);
	CPPUNIT_TEST(test_operation_container);
	CPPUNIT_TEST(test_parameter_container);
	CPPUNIT_TEST(test_property_container);
	CPPUNIT_TEST(test_class_container);
	
	CPPUNIT_TEST_SUITE_END();

private:
	Gmof::Package* package;
	Gmof::Class*   klass;

public:
	void setUp()
	{
		package = new Gmof::Package("ClassTest", "com.googlecode.gmof.test.class");
		klass = new Gmof::Class("TestClass", package);
	}

	void tearDown()
	{
		klass->unreference();
		package->unreference();
	}

	void test_creation()
	{
		CPPUNIT_ASSERT(package);
		CPPUNIT_ASSERT(klass);
	}	

	void test_property_creation()
	{
		Gmof::Property* name = new Gmof::Property("name", klass);
		
		CPPUNIT_ASSERT(klass->owned_attribute->size() == 1);
		CPPUNIT_ASSERT(name->klass == klass);
	}	

	void test_operation_creation()
	{
		Gmof::String* string = new Gmof::String("string", package); 
		Gmof::Operation* get_name = new Gmof::Operation("get_name", string, klass);
		
		CPPUNIT_ASSERT(klass->owned_operation->size() == 1);
		CPPUNIT_ASSERT(get_name->klass == klass);
	}	

	void test_parameter_creation()
	{
		Gmof::String* string = new Gmof::String("String", package);
		Gmof::Operation* set_name = new Gmof::Operation("set_name", NULL, klass);
		Gmof::Parameter* name = new Gmof::Parameter("name", string, set_name);
		
		CPPUNIT_ASSERT(set_name->owned_parameter->size() == 1);
		CPPUNIT_ASSERT(name->operation == set_name);
		CPPUNIT_ASSERT(name->type == string);
	}
	
	void test_comment_container()
	{
		Gmof::Comment* comment = new Gmof::Comment("Test comment");
		CPPUNIT_ASSERT(comment->container() == NULL);
		
		comment->unreference();
	}
	
	void test_operation_container()
	{
		Gmof::Operation* operation = new Gmof::Operation("foo", NULL, klass);
		
		CPPUNIT_ASSERT(operation->container() == klass);
	}

	void test_parameter_container()
	{
		Gmof::String* string = new Gmof::String("String", package); 
		Gmof::Operation* operation = new Gmof::Operation("foo", NULL, klass);
		Gmof::Parameter* param = new Gmof::Parameter("bar", string, operation);
		
		CPPUNIT_ASSERT(param->container() == operation);
	}
	
	void test_property_container()
	{
		Gmof::Property* prop = new Gmof::Property("foo", klass);
		
		CPPUNIT_ASSERT(prop->container() == klass);
	}
	
	void test_class_container()
	{
		CPPUNIT_ASSERT(klass->container() == package);
	}
};

//CPPUNIT_TEST_SUITE_REGISTRATION(ClassTest);

// End of file
